#include <stdio.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"

static void *example_task_run(void *data){
    char *s = (char *)data;
    for (int i = 0; i < 10; i++)
    {
        sleep(1);
        printf("\n\r\n%s:%d!\r\n",s,i);
    }
    return data;
    
}

void example_task(void){
    osThreadAttr_t attr1;
    osThreadAttr_t attr2;
    attr1.name = "example_task1";
    attr1.attr_bits = 0U;
    attr1.cb_mem = NULL;
    attr1.cb_size = 0U;
    attr1.stack_mem = NULL;
    attr1.stack_size = 1024;
    attr1.priority = osPriorityNormal;

    attr2.name = "example_task2";
    attr2.attr_bits = 0U;
    attr2.cb_mem = NULL;
    attr2.cb_size = 0U;
    attr2.stack_mem = NULL;
    attr2.stack_size = 1024;
    attr2.priority = osPriorityNormal;

    if (osThreadNew((osThreadFunc_t) example_task_run,"example_task1",&attr1)==NULL)
    {
        printf("Example_task1 create failed.\n");
    }
    
    if (osThreadNew((osThreadFunc_t) example_task_run,"example_task2",&attr2)==NULL)
    {
        printf("Example_task2 create failed.\n");
    }
}

SYS_RUN(example_task);